<?php

require_once './include/common.inc.php';

getMyParam('categoryid');

if (!is_numeric($categoryid) || $categoryid <= 0) {
    header("Location:photo.php");
    exit;
}

$page_title = 'jans2en furniture - 相片图库 - 相片图库';
$menu_id = 3;


$photo_ary = array();
$sql = "SELECT `id`, `name`, `pic` FROM `photo` WHERE `photo_category_id`=$categoryid  AND `type`=0 ORDER BY `seq` ASC, `id` DESC";

//Image to json array;
$scriptImg = "jsonImg = {\"data\":[";
$jsonFormat = "{\"name\":\"%s\",\"src\":\"%s\"}";
$aryPhoto = array();
$strSep = '';
$query = $db->query($sql);
$i=0;
while($rs = $db->fetch_array($query)) {
	if($rs["pic"]!="" && file_exists("attachments/".$rs["pic"]))
	{
		$scriptImg .= $strSep.sprintf($jsonFormat,$rs["name"],"attachments/".$rs["pic"]);	
		$rs["pic"] = "attachments/".$rs["pic"];
	}
	else
	{
		$scriptImg .= $strSep.sprintf($jsonFormat,$rs["name"],"attachments/noCN.gif");	
		$rs["pic"] = "attachments/noCN.gif";
	}
	//fetch 9 records to show in frant end;
	$i++;
	if($i<=9)
	{		
		$aryPhoto[]= $rs;
	}
	$strSep = ',';
}
$scriptImg .= "]};";

$photo_category_ary = array();
$sql = "SELECT `id`, `name` FROM `photo_category` ORDER BY `seq` ASC, `id` DESC";
$query = $db->query($sql);
while($rs = $db->fetch_array($query)) {
    $photo_category_ary[$rs['id']] = $rs['name'];
}

$select_str = '';
foreach ($photo_category_ary as $k=>$v) {
    $selected = "";
    if ($k == $categoryid) {
        $selected = "selected";
    }
    $select_str .= '<option value="' . $k . '" ' . $selected . '>' . $v . '</option>';
}



browseTracking(13,0,'Photo Gallery > '.$photo_category_ary[$categoryid].'(page '.$page.')');

$postiondiv='<div class="position"><a href="index.php">首页</a> &gt; <span class="position">相片图库</span></div>';
$baner_img='<div class="bigtitle">相片图库</div>';

	
require_once PrintEot('header');
require_once PrintEot('photo_view');
require_once PrintEot('footer');

?>